package com.order.api.controller;

import com.order.api.service.AdminUserService;
import com.order.api.target.Authorization;
import com.order.api.target.MethodLog;
import com.order.api.vo.BaseResult;
import com.order.api.vo.request.PwdChangeRequest;
import com.order.api.vo.request.UserFindRequest;
import com.order.api.vo.request.UserLoginRequest;
import com.order.api.vo.request.UserSaveRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "登录模块")
@RequestMapping("/admin")
@RestController
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    @ResponseBody
    @ApiOperation("用户登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @MethodLog(optType = "用户登录",systemModel ="登录模块" )
    public BaseResult<String> login (@RequestBody UserLoginRequest request){
        return  BaseResult.success("登录成功", adminUserService.adminUserLogin(request));
    }

    @ApiOperation("用户注册")
    @Authorization
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @MethodLog(optType = "用户注册",systemModel = "登录模块")
    public BaseResult<String> save(@RequestBody  UserSaveRequest request){
        return BaseResult.judgeOperate(adminUserService.saveUSer(request));
    }

    @Authorization
    @ApiOperation("重置密码")
    @RequestMapping(value = "/reset/password",method = RequestMethod.POST)
    @MethodLog(optType = "重置密码",systemModel = "登录模块")
    public BaseResult<String> resetPassword(@RequestBody UserFindRequest request){
        return BaseResult.judgeOperate(adminUserService.resetPassword(request));
    }

    @Authorization
    @ApiOperation("改变密码")
    @RequestMapping(value = "/change/password",method = RequestMethod.POST)
    @MethodLog(optType = "改变密码",systemModel = "登录模块")
    public BaseResult<String> changePassword(@RequestBody PwdChangeRequest request){
        return BaseResult.judgeOperate(adminUserService.changePassword(request));
    }

    @Authorization
    @ApiOperation("退出登录")
    @RequestMapping(value = "/logout",method = RequestMethod.POST)
    @MethodLog(optType = "退出登录",systemModel = "登录模块")
    public BaseResult<String> logout(){
        return BaseResult.judgeOperate(adminUserService.logout());
    }
}
